#ifndef _RECORD_NORMAL_H_
#define  _RECORD_NORMAL_H_

#include <string>
#include <map>
#include <mutex>
#include <thread>
#include "common/ptmfrm_fifo.h"
#include <atomic>
#include "STFS_com.h"
#include "indexSet.h"
using namespace std;
//常规全时录像
class CRecord_mp4_blk
{
public:
	CRecord_mp4_blk();
	~CRecord_mp4_blk();
	int Init(string file_path, string file_ext,int stream_id,int packet_sec);
	int Start(int stream_id=-1);
	int Stop();
	void set_pkt_sec(int packet_sec)
	{
		m_packet_sec = packet_sec;
	}
	int get_pkt_sec()
	{
		return m_packet_sec;
	}
	void set_res(int width,int height)
	{
		m_width = width;
		m_height = height;
	}
	void set_frame_rate(int rate)
	{
		m_frame_rate = rate;
	}
	void set_preparesec(int sec)
	{
		m_prepare_sec = sec;
	}
	int get_preparesec()
	{
		return m_prepare_sec;
	}
	void show_log(bool bEnable)
	{
		m_show_log = bEnable;
	}

	const char * get_rec_path()
	{
		return m_storage_path.c_str();
	}
	void AttachFrame(CFIFO_PTMFrame * pFrame)
	{
		m_pFrame = pFrame;
	}
	
	int     m_stream;
	static mutex st_cycle_mutex;
protected:
	int  DataProcThread();
	int  check_path(const char * mnt_path);
	int  get_usb_path(char * dev, char * usb_path);
	int  GetNextFileName(string & filePath,int64_t start_tm,int event_id);
	void rec_mark_start(uint32_t file_idx,int64_t start_tm, int record_type = RECORD_MANUAL);
	void rec_mark_end(uint32_t file_idx, int64_t end_tm, uint32_t file_sz);
	thread  m_recThd;
	bool    m_bStart;
	bool    m_bOpen;
	int     m_event_id;
	int64_t m_start_tm;
	int     m_width;
	int     m_height;
	int     m_frame_rate;
	int     m_packet_sec;
	int     m_prepare_sec;
	int     m_file_type;
	uint32_t m_fileIndex;
	uint32_t m_file_len = 0;
	char    m_file_ext[6];
	char    m_event_name[64];
	mutex   m_mutex;
	string  m_storage_path;
	string  m_destDev;
	uint16_t     m_disk_no;
	int     m_cycle_percent = 5; //回收比例
	int     m_client_id;
	char    m_disk_dev[64];
	int     m_channel;
	static int st_fill_len;
	atomic_bool m_pkting;
	bool    m_show_log;
	CFIFO_PTMFrame * m_pFrame;
	REC_FILE_INFO	m_recSegInfo;

	CIndexSet*  m_pRecIndexSet;
};
#endif
